package me.sealer.jmx.agent;

import lombok.extern.slf4j.Slf4j;
import me.sealer.jmx.mbean.QueueInspector;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;

/**
 * MXBean
 * 可用jconsole查看
 * @author sealer
 * @date 2018/01/22.
 */
@Slf4j
public class QueueAgent {
    public static void startAgent() throws Exception {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName objectName = new ObjectName("me.sealer:type=QueueInspector");
        Queue<String> queue = new ArrayBlockingQueue<>(8);
        queue.add("Request-1");
        queue.add("Request-2");
        queue.add("Request-3");
        QueueInspector mxBean = new QueueInspector(queue);
        server.registerMBean(mxBean, objectName);
        log.debug("waiting...");
        Thread.sleep(Long.MAX_VALUE);
    }

    public static void main(String[] args) throws Exception {
        startAgent();
    }
}
